package com.lzb.newloan;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzb.newloan.bqs.CatLoadingView;
import com.lzb.newloan.utils.BaseActivity;

public class ProblemActivity extends BaseActivity implements OnClickListener {

	private String url = "https://www.dianrong.com/mkt/bor_mojie_v9/index.html?clientsourcetype=BD&referredBy=d_bixiakuan";
	private WebSettings webSettings;
	private WebView home_webview;
	private CatLoadingView dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_problem);
		initView();
	}

	private void initView() {
		dialog = new CatLoadingView(ProblemActivity.this);
		dialog.show();
		Intent intent = getIntent();
		url = intent.getStringExtra("url");
		TextView title_txt_center = (TextView) findViewById(R.id.title_txt_center);
		title_txt_center.setText(intent.getStringExtra("title"));
		
		RelativeLayout backpress = (RelativeLayout) findViewById(R.id.backpress);
		backpress.setOnClickListener(this);

		home_webview = (WebView) findViewById(R.id.webview);
		webSettings = home_webview.getSettings();
		webSettings = home_webview.getSettings();
		// home_webview.setScrollBarStyle(0);
		webSettings.setDomStorageEnabled(true);
		// 支持javascript
		webSettings.setJavaScriptEnabled(true);
		// 设置可以支持缩放
		webSettings.setSupportZoom(true);
		// 设置出现缩放工具
		webSettings.setBuiltInZoomControls(false);
		// 扩大比例的缩放
		webSettings.setUseWideViewPort(true);
		// 自适应屏幕
		webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
		webSettings.setLoadWithOverviewMode(true);
		home_webview.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageFinished(WebView view, String url) {
				if (!webSettings.getLoadsImagesAutomatically()) {
					webSettings.setLoadsImagesAutomatically(true);
				}
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				// TODO Auto-generated method stub
				super.onPageStarted(view, url, favicon);
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				dialog.show();
				view.loadUrl(url);// 载入网页

				return true;
			}
		});
		home_webview.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {// 载入进度改变而触发
				if (progress == 100) {
					dialog.dismiss();
				}
				super.onProgressChanged(view, progress);
			}

		});

		home_webview.loadUrl(url);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.backpress:
			finish();
			break;
		default:
			break;
		}
	}

	@Override
	public void processMessage(Message message) {
		// TODO Auto-generated method stub
		
	}
}
